使用JavaScript更改CSS偽元素


Posted by hoyi-23 on 2021-06-17

這裡提供一個很簡單的作法:

HTML

<div class="box" some-attribute-name=""></div>

CSS

.box::before{
    content= attr(some-attribute-name);
}

JavaScript

var box = document.querySelector('.box');
box.setAttribute('some-attribute','要新增的屬性值');

#偽元素 #javascript







Related Posts

筆記、前後端基礎概念

筆記、前後端基礎概念

React hook form(1) - useForm & 它的回傳值(1)

React hook form(1) - useForm & 它的回傳值(1)

【JS 大魔王 - 2】Hoisting 可以幹嘛?

【JS 大魔王 - 2】Hoisting 可以幹嘛?


Comments